import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# 假设的特征重要性系数
feature_importances = np.array([0.2, 0.1, -0.05, 0.3, -0.15])
# 假设的特征名称
feature_names = ['Feature1', 'Feature2', 'Feature3', 'Feature4', 'Feature5']

# 创建数据框
data = {'Feature': feature_names, 'Importance': feature_importances}
importances_df = pd.DataFrame(data)

# 按照重要性绝对值排序
importances_df = importances_df.reindex(importances_df['Importance'].abs().sort_values(ascending = False).index)

# 绘制条形图
plt.figure(figsize=(10, 6))
sns.barplot(x = 'Importance', y = 'Feature', data = importances_df)
plt.title('Feature Importances')
plt.show()